package day07;

import java.util.Stack;

/**
 * 定义栈的数据结构，请在该类型中实现一个能够得到栈最小元素的min函数。
 * 
 * @author Administrator
 *
 */
public class Test02 {
	Stack<Integer> stack = new Stack<Integer>();
	Stack<Integer> stack2 = new Stack<Integer>();

	private int min = Integer.MAX_VALUE;

	public void push(int node) {

		stack.push(node);
		if (min >= node) {
			this.min = node;
			stack2.add(min);
		}
	}

	public void pop() {
		if (stack.peek() == stack2.peek()) {
			stack2.pop();
			this.min = stack2.peek();
		}
		stack.pop();
	}

	public int top() {
		return stack.peek();
	}

	public int min() {
		return this.min;
	}
}
